#ifndef __CSINGLETON_H__
#define __CSINGLETON_H__

#include <stdio.h>

template <typename T>
class CSingleton
{
public:

    inline static T* GetInstance()
    {
        return m_instance;
    }

	static T* CreateInstance()
	{
		if (!m_instance)
		{
			 m_instance = new T;
			 return m_instance;
		}
		else
		{
			return m_instance;
		}
	}

    static void DestroyInstance()
    {
		if (m_instance)
		{
	        delete m_instance;
		    m_instance = NULL;
		}
    }

protected:

    CSingleton() {}
    virtual ~CSingleton() {}

private:

    CSingleton(const CSingleton& source) {}

    static T* m_instance;
};

template <typename T> T* CSingleton<T>::m_instance = 0;

#endif
